package com.xiaoxin.controller;

import com.xiaoxin.model.vo.PageResult;
import com.xiaoxin.service.SmallVideosService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideosService videosService;


    /*
     *  发布视频
     *  接口路径：POST
     *  请求参数：
     *  videoThumbnail：封面图
     *  videoFile：视频文件
     */
    @PostMapping
    public ResponseEntity saveVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videosService.saveVideos(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    /*
     * 视频列表
     */
    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = videosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /*
    * 视频用户关注
    * */
    @PostMapping("/{id}/userFocus")
    public ResponseEntity userFocus(@PathVariable("id") Long videoId){
        videosService.userFocus(videoId);
        return ResponseEntity.ok(null);
    }


    /*
    * 视频用户取消关注
    * */
    @PostMapping("/{id}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("id") Long videoId){
        videosService.userUnFocus(videoId);
        return ResponseEntity.ok(null);
    }

    /*
    * 视频点赞
    * */
    @PostMapping("/{id}/like")
    public ResponseEntity videolike(@PathVariable("id") ObjectId videoId){
        videosService.videolike(videoId);
        return ResponseEntity.ok(null);
    }


    /*
    * 视频取消点赞
    * */
    @PostMapping("/{id}/dislike")
    public ResponseEntity videodislike(@PathVariable("id") ObjectId videoId){
        videosService.videodislike(videoId);
        return ResponseEntity.ok(null);
    }
}